package www.xudan.chartdemo;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Description;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        LineChart mLineChart = (LineChart) findViewById(R.id.lineChart);
        XAxis xAxis = mLineChart.getXAxis();
        //设置X轴的文字在底部
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        //设置描述文字
        Description description = new Description();
        description.setText("x周描述");
        mLineChart.setDescription(description);
        mLineChart.setDrawGridBackground(true);
        ArrayList<String> x_list = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            x_list.add("10-20");
            x_list.add("20-30");
            x_list.add("30-40");

        }

        ArrayList<Entry> xy_list = new ArrayList<>();
        for (int i = 0; i < 7; i++) {
            xy_list.add(new Entry(i, i));
        }

        ArrayList<String> y_list = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            y_list.add("男生");
            y_list.add("女生");
            y_list.add("老人");
            y_list.add("小孩");

        }

        LineDataSet lineDataSet = new LineDataSet(xy_list, "");
        LineData lineData = new LineData(lineDataSet);
        mLineChart.setData(lineData);
    }
}
